﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;


namespace fingerWinForm.UpdrsTests
{
    class GeneralCalc
    {

        static public List<int> generateRandomNumbers(int range, double percentage, double totalNumber)
        {
            Random rand = new Random();
            List<int> result = new List<int>();
            for (int i = 0; i < Math.Floor((percentage * totalNumber) / 100); i++)
            {
                int curValue = rand.Next(0, range);
                while (result.Exists(value => value == curValue))
                {
                    curValue = rand.Next(1, range);
                }
                result.Add(curValue);
            }
            return result;
        }


        static public float calcRatio(float a, int b)
        {
            return (a / b);
        }
        
        static public float calcRatio(float a, float b)
        {
            return (a / b);
        }

        static public float calcSumDiviation(float avg, List<float> listPassed)
        {
            float sum = 0;
            float result =0;
                    
            foreach (float sumtimeopen in listPassed)
                {
                    sum += (float)Math.Pow((double)Math.Abs(sumtimeopen - avg), 2);
                }
            result = (float)Math.Sqrt((double)sum / listPassed.Count); 
            return result;
        }
        static public float calcSkewness(float avg,float avgDeviation, List<float> listPassed)
        {
            float sum = 0;
            float result = 0;

            foreach (float value in listPassed)
            {
                sum += (float)Math.Pow((double)Math.Abs(value - avg), 3);
            }
            result = (float)(sum / ((listPassed.Count - 1) * (float)Math.Pow((double)avgDeviation, 3)));
            return result;
        }
        static public float calcKurtosis(float avg, float avgDeviation, List<float> listPassed)
        {
            float sum = 0;
            float result = 0;

            foreach (float value in listPassed)
            {
                sum += (float)Math.Pow((double)Math.Abs(value - avg), 4);
            }
            result = (float)(sum / ((listPassed.Count - 1) * (float)Math.Pow((double)avgDeviation, 4)));
            return result;
        }
        static public float calcAvg(List<float> fingerRecognizedCounterList)
        {
            float sum = 0;

            foreach (float fingersRecognized in fingerRecognizedCounterList)
            {
                sum += fingersRecognized;
            }

            return sum / fingerRecognizedCounterList.Count;
        }
    }
}
